//
//	Created By Pavel Yankelevich
//	Thursday, March 20, 2008
//
using System;
using fit;
using OneDayModel.Interfaces;
using OneDayModel.Tests.Fits.UIUsers;

namespace OneDayModel.Tests.Fits.Fixtures.Scenarios
{
    public class UserLoginFixture : Fixture
    {
        private string alias;
        private string password;
        private UserLoginUser userLoginUser;
        private string thrownException = string.Empty;

        public void Alias(string aliasToSet)
        {
            alias = aliasToSet;
        }

        public void Password(string passwordToSet)
        {
            password = passwordToSet;
        }

        public void Login()
        {
            UsersFactory userFactory =
                (UsersFactory)TestUtils.ContextManager.TestContext[typeof(UsersFactory).ToString()];
            userLoginUser = userFactory.GetUserLoginUser();

            userLoginUser.SetAlias(alias);
            userLoginUser.SetPassword(password);

            try
            {
                userLoginUser.LoginUser();
            }
            catch(Exception ex)
            {
                thrownException = ex.Message;
            }
        }

        public string ShownPage()
        {
            return userLoginUser.ShownPage + (userLoginUser.user!=null ? " For " + userLoginUser.user["Alias"] : "");
        }

        public string ThrownException()
        {
            return thrownException;
        }
    }
}